using System;
using System.Configuration;

namespace SQLRunnerLib.Util
{
    public class PlaceHolderCollection : ConfigurationElementCollection
    {
        public override ConfigurationElementCollectionType CollectionType
        {
            get{ return ConfigurationElementCollectionType.AddRemoveClearMap; }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new PlaceHolderElement();
        }

        
        protected override ConfigurationElement CreateNewElement(string elementName)
        {
            return new PlaceHolderElement(elementName);
        }
        

        protected override Object GetElementKey(ConfigurationElement element)
        {
            return ((PlaceHolderElement)element).PlaceHolder;
        }

        public new string AddElementName
        {
            get{ return base.AddElementName; }
            set{ base.AddElementName = value; }
        }

        public new string ClearElementName
        {
            get{ return base.ClearElementName; }
            set{ base.AddElementName = value; }
        }

        public new string RemoveElementName
        {
            get{ return base.RemoveElementName; }
        }

        public new int Count
        {
            get { return base.Count; }
        }

        public PlaceHolderElement this[int index]
        {
            get { return (PlaceHolderElement)BaseGet(index); }
            set
            {
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }

        new public PlaceHolderElement this[string Name]
        {
            get
            {
                return (PlaceHolderElement)BaseGet(Name);
            }
        }

        public int IndexOf(PlaceHolderElement url)
        {
            return BaseIndexOf(url);
        }

        public void Add(PlaceHolderElement url)
        {
            BaseAdd(url);
        }

        protected override void BaseAdd(ConfigurationElement element)
        {
            BaseAdd(element, false);
        }

        public void Remove(PlaceHolderElement url)
        {
            if (BaseIndexOf(url) >= 0)
                BaseRemove(url.PlaceHolder);
        }

        public void RemoveAt(int index)
        {
            BaseRemoveAt(index);
        }

        public void Remove(string name)
        {
            BaseRemove(name);
        }

        public void Clear()
        {
            BaseClear();
        }
    }
}